home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1805 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: rap.SanDiegoCA.ATTGIS.COM!es013!jbc
  2. From: jbc@ElSegundoCA.ATTGIS.COM (Jim Chapman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Using multiple functions in one file
  5. Date: 13 Jan 1996 01:04:28 GMT
  6. Organization: AT&T Global Information Solutions
  7. Distribution: world
  8. Message-ID: <4d70es$gig@rap.SanDiegoCA.ATTGIS.COM>
  9. Reply-To: jbc@ElSegundoCA.ATTGIS.COM
  10. NNTP-Posting-Host: es013.elsegundoca.attgis.com
  11.  
  12. In article 31EA@sierra.net, T Colwell <snowbull@sierra.net> () writes:
  13. > Andrew Belo wrote:
  14. > > 
  15. > > I have written an example program out of a book and it keeps giving me an
  16. > > error that says "Call to undefined function 'butler' in function main()"
  17. > > I am using Borland C++ for Dos, Win and Win 32 Version 4.5.
  18. > > 
  19. > > The book is called C: Step by Step, and the program is as follows.
  20. > > 
  21. > > /* two_func.c -- a program using two functions in one file */
  22. > > #include <stdio.h>
  23. > > main()
  24. > > {
  25. > >         printf("I will summon the butler function. \n");
  26. > >         butler();
  27. > >         printf("Yes. Bring me some tea and floppy disks.\n");
  28. > > }
  29. > > butler()
  30. > > {
  31. > > printf("You rang, sir? \n");
  32. > > }
  33. > > 
  34. > ------
  35. > Try placing butler() before main() and recompiling.
  36.  
  37.  
  38. That would work, but it might be helpful to explain that this is a perfectly
  39. legal C program; it just doesn't happen to be legal C++.  C allows a
  40. function to be called before (lexically speaking) it is defined. The 
  41. function is then considered implicitly declared as returning int. C++
  42. requires that the function declaration appear before the function call.
  43.  
  44. ---
  45.  ====  AT&T        | Jim Chapman             |
  46. =--=== Global      | Multimedia Projects     | jbc@ElSegundoCA.ATTGIS.COM
  47. =--=== Information | 100 N. Sepulveda Blvd.  |   Voice: (310) 524-6747          
  48.  ====  Solutions   | El Segundo, CA 90245    |   FAX:   (310) 524-5515
  49.  
  50.